<template>
  <div>
    <m-head title="最新通知"></m-head>
    <div class="list">
      <div class="item" v-for="item in list" :key="item.id" @click="$router.push({path:'/newsdetail',query:{info:item}})">
        <div class="title">
          <h3>{{item.title}}</h3>
          <span>{{t2s(item.created_at)}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import MHead from './MHeader'
import * as info from '../api/info'
import * as t from '../utils/time'
export default {
  name: 'news',
  data: function () {
    return {
      list: [
        {
          id: 0,
          show: false,
          name: '关于公司年会的通知',
          time: '2019-01-02'
        },
        {
          id: 1,
          show: false,
          name: '关于春节假期的通知',
          time: '2019-01-02'
        }
      ]
    }
  },
  components: {
    'm-head': MHead
  },
  mounted () {
    this.getNews()
  },
  methods: {
    getNews () {
      info.getNews().then(res => {
        console.log(res)
        this.list = res.data
      })
    },
    t2s(time){
      return t.t2s(time)
    }
  }
}
</script>

<style scoped>

  .item{
    border-bottom: 1px solid #eee;
  }
  .item .title{
    height: 1.2rem;
    padding: 0 .3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .item h3{
    font-size: .4rem;
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .item span{
    color: #888;
    flex-shrink: 0;
    margin-left: .3rem;
  }
</style>
